<?php
/**
 *
 *
 * This file is part of Webappkit, a packages system for PHP web apps
 * @link http://webappkit.net
 * @package
 * @subpackage
 * @author J.Ducastel <nospam0@ducastel.name>
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 */

/**
 * a storage interface for DjModel objects
 */
interface iDjManager extends Iterator {

    /**
     * Filters current selection on a key/value pair
     *
     * @param  string $key
     * @param  mixed $value
     * @return DjManager a copy with of itself + filter applied
     */
    public function filter($key, $value);

    /**
     * Applies a list of filters, grouped in associative array, to the selection
     *
     * @param array $filters
     * @return bool True if all filters have been applied
     * /
    public function filters($filters);/**/

    /**
     * Count items belonging to the current selection
     *
     * @return int
     */
    public function count();

    /**
     * Return items belonging to the current selection
     *
     * @return array
     */
    public function all();

    /**
     * Get an item, either the first in selection or by primary key
     *
     * @param  mixed $key primary key value.
     * if null, will return the first item in selection
     * @return DjModel
     */
    public function get($key=null);

    /**
     * Insert an object into the collection
     *
     * Updates object if necessary (set auto-incremented key, etc)
     *
     * @param DjModel $item
     * @return bool
     */
    public function insert(&$item);

    /**
     * Update an object within the collection
     *
     * Updates object if necessary (set auto-incremented key, etc)
     *
     * @param  object $item
     * @return bool
     */
    public function update(&$item);

    /**
     * Remove an object from the collection
     *
     * @param  object $item
     * @return bool
     */
    public function remove($item);
}

interface iDjModel {

    /**
     * get the objects manager
     * all subclasses have to implement their own !!
     * @return DjManager
     */
    public static function objects();

    /**
     * save object in storage / database
     * @param string $mode insert|update
     * @return bool
     */
    public function save($mode=null);

    /**
     * destroy object in storage / database
     * @return bool
     */
    public function delete();
}